<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" style="width:220px" />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <!--        <img :src="userInfo.staffPhoto">-->
        <uploadImg v-model="userInfo.staffPhoto" />
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="hSave">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserId } from '@/api/user'
import { saveUserDetailById } from '@/api/employees.js'
// 导入子组件
import uploadImg from '@/components/uploadImg/index'
export default {
  name: 'UserInfo',
  // 导入组件名
  components: { uploadImg },
  // 父传子,接收变量名
  props: {},
  data() {
    // 这里存放数据
    return {
      userId: this.$route.query.id,
      userInfo: {
        mobile: '',
        timeOfEntry: ''
      }
    }
  },
  // 计算属性 类似于 data 概念
  computed: {},
  // 监听器 监控 data 中的数据变化
  watch: {},
  created() {
    this.loadUserInfo()
  },
  // 方法集合
  methods: {
    // 获取员工详情
    async loadUserInfo() {
      try {
        const res = await getUserId(this.userId)
        console.log('getUserId', res)
        this.userInfo = res.data
      } catch (err) {
        console.log('getUserId', err)
      }
    },
    // 更新员工信息
    async hSave() {
      try {
        const res = await saveUserDetailById(this.userInfo)
        console.log(res)
        this.$router.back()
      } catch (e) {
        console.log(e)
      }
    }
  }

}
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
<style scoped lang="scss">
.user-info{
  padding-top:20px;
}
</style>
